<script>
import { mapMutations } from 'vuex';
export default {
	methods: {
		...mapMutations(['login'])
	},
	onLaunch: function() {},
	onShow: function(options) {
		// Removed window.location.href reference that causes errors in MiniProgram environment
		// 如果支付方式是跳转到PayJS支付小程序进行支付
		// 针对场景值为 1038、来源appid 为wx959c8c1fb2d877b5、跳转到的页面id 为发起支付的页面，则标记为支付成功、记录支付的 payjs_order_id
		if (options.scene === 1038 && options.referrerInfo && options.referrerInfo.appId === 'wx959c8c1fb2d877b5') {
			// 由于我们已经在支付请求时完成了订单支付，这里不需要额外处理
			// 仅需处理参数中包含auto_success=true的情况，直接跳转到取餐页面
			let extraData = options.referrerInfo.extraData;
			console.log(extraData)
			if (extraData && extraData.auto_success === "true") {
				console.log("已自动处理支付成功")
				// 直接跳转到取餐页面
				uni.reLaunch({
					url: '/pages/take-foods/take-foods'
				});
			} else {
				// 老的支付流程，保持兼容
				this.globalData.paySuccess = extraData.success;
				this.globalData.resultCode = extraData.resultCode;
				this.globalData.msg = extraData.msg;
				this.globalData.payjsOrderId = extraData.payjsOrderId;
				let that = this;
				let data = {
					"outTradeNo": extraData.outTradeNo,
					"payjsOrderId": extraData.payjsOrderId,
					"resultCode": extraData.resultCode,
					"success": extraData.success,
				}
				that.$request("/order/finishWeixinPay", "PUT", data).then(res=>{
					console.log("支付成功", res)
				})
			}
		}
	},
	onHide: function() {
		console.log('App Hide');
	}
};
</script>

<style lang="scss">
/*每个页面公共css */
@import '~@/static/style/app.scss';
</style>

